﻿
DateTime Time1 = DateTime.Now;
int[] Primenumbers = new int[100000];
//数组下标
int count = 0;
Primenumbers[count] = 2;
count++;
for (int i = 3; i < 100000; i++)
{
    //排除偶数
    if (i % 2 == 0) continue;
    //利用数组判断一个数是否为质数
    for (int j = 0; j < 100000 && Primenumbers[j] != 0; j++)
    {
        if (i % Primenumbers[j] == 0)
            //当i不是质数时，跳出循环
            goto nextstep;
    }
    Primenumbers[count] = i;
    count++;
nextstep: continue;
}
int max = 0;
for (int i = 0; i < Primenumbers.Length - 1; i++)
{
    if (Primenumbers[i + 1] > Primenumbers[max])
        max = i + 1;
}
/// 另一种方式for (int i = 0; Primenumbers[i] != 0; i++)max = i;
Console.WriteLine("最大的质数为" + Primenumbers[max]);
DateTime Time2 = DateTime.Now;
TimeSpan Time3 = Time2 - Time1;
int Milliseconds = Time3.Milliseconds;
Console.WriteLine("程序运行时间为" + Milliseconds + "毫秒");





